var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listCategoryOne: [],
    categoryParentid:"",
    categorySelect: "",
    name: "",
    minPrice:"",
    maxPrice:"",
    buthidden: true,
    yz1:"",
    yz2: "",
    yz3: "",
    yz4: false
  },
  inputname:function(e){
    var that = this;
    if (e.detail.value == '') {
      that.setData({
        yz1: false,

      })
    } else {
      that.setData({
        yz1: true,

      })
    }
    console.log(that.data.yz1 != '' && that.data.yz2 != '' && that.data.yz3 != '' && that.data.yz4 == true)
    if (that.data.yz1 != '' && that.data.yz2 != '' && that.data.yz3 != '' && that.data.yz4 == true) {
      that.setData({
        buthidden: false,

      })
      
    } else {
      that.setData({
        buthidden: true,

      })
    }
    that.setData({
      name: e.detail.value
    })
  },
  bindFormSubmit: function () {
    var that = this;
    wx.request({
      method: "POST",
      url: app.preUrl + 'saveSiteCategory',//新增类目
      dataType: 'json',
      header: {
        'content-type': 'application/x-www-form-urlencoded;',
      },
      data: {
        userId: app.globalData.userId,
        parentId: that.data.categorySelect,
        name: that.data.name,
        minimumPrice: that.data.minPrice,
        highestPrice: that.data.maxPrice,
      },
      success: function (res) {
        console.log(res)
      },
      fail: function (error) {
        console.log("error", error);
      }
    })

    wx.navigateBack({
      delta: 1,
     
    })
  }, 

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    console.log(that.data.yz1 == '' && that.data.yz2 == '' && that.data.yz3 == '' && that.data.yz4 == true)
    if (that.data.yz1 == '' && that.data.yz2 == '' && that.data.yz3 == '' && that.data.yz4 == true){
      that.setData({
        buthidden: true
      })
    }
  },
  //一级菜单选择
  categoryList: function (e) {
    var that = this;
    that.setData({
      yz4: true
    })
    if (that.data.yz1 != '' && that.data.yz2 != '' && that.data.yz3 != '' && that.data.yz4 == true) {
      that.setData({
        buthidden: false,

      })

    } else {
      that.setData({
        buthidden: true,

      })
    }
    that.setData({//把选中值放入判断值
      categorySelect: e.currentTarget.dataset.select,
      categoryParentid: e.currentTarget.dataset.parentid,
    });
  },

  //录入最低价
  onMinPrice: function (e) {
    var that = this;
    if (e.detail.value == '') {
      that.setData({
        yz2: false,
       
      })
    } else {
      that.setData({
        yz2: true,
       
      })
    }
    console.log(that.data.yz1 != '' && that.data.yz2 != '' && that.data.yz3 != '' && that.data.yz4 == true)
    if (that.data.yz1 != '' && that.data.yz2 != '' && that.data.yz3 != '' && that.data.yz4 == true) {
      that.setData({
        buthidden: false,

      })

    } else {
      that.setData({
        buthidden: true,

      })
    }
    that.setData({ minPrice: e.detail.value.replace(/[^\d.]/g, "") });
    that.setData({ minPrice: e.detail.value.replace(/\.{2,}/g, ".") });
    that.setData({ minPrice: e.detail.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".") });
    that.setData({ minPrice: e.detail.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3') });
  },

  //录入最高价
  onMaxPrice: function (e) {
    var that = this;
    if (e.detail.value == '') {
      that.setData({
        yz3: false,
        
      })
    } else {
      that.setData({
        yz3: true,
       
      })
    }
    console.log(that.data.yz1 != '' && that.data.yz2 != '' && that.data.yz3 != '' && that.data.yz4 == true)
    if (that.data.yz1 != '' && that.data.yz2 != '' && that.data.yz3 != '' && that.data.yz4 == true) {
      that.setData({
        buthidden: false,

      })

    } else {
      that.setData({
        buthidden: true,

      })
    }
    that.setData({ maxPrice: e.detail.value.replace(/[^\d.]/g, "") });
    that.setData({ maxPrice: e.detail.value.replace(/\.{2,}/g, ".") });
    that.setData({ maxPrice: e.detail.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".") });
    that.setData({ maxPrice: e.detail.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3') });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.showLoading({
      title: '拼命加载中',
      mask: true
    })
    wx.request({
      method: "POST",
      url: app.preUrl + 'getSysCategoryList',//一级分类
      header: {
        'content-type': 'application/x-www-form-urlencoded;',
      },
      success: function (res) {
        wx.hideLoading();
        that.setData({ listCategoryOne: res.data.result });
      },
      fail: function (error) {
        console.log("error", error);

      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})